#!/usr/bin/env python
# encoding: utf-8
import os

"""
功能：相当于mkdir -p的效果
"""
def mkdirx( newdir ):
    if os.path.isdir( newdir ):
        pass
    elif os.path.isfile( newdir ):
        raise OSError( "a file with the same name as desired, '%s', already exsits." % ( newdir ) )
    else:
        head, tail = os.path.split( newdir )
        if head and not os.path.isdir( head ):
            mkdirx( head )
        if tail:
            os.mkdir( newdir )
"""
功能：删除文件夹及其下的所有子文件夹、文件
"""
def rmdirx( dir ):
    files = os.listdir( dir )
    for file in files:
        path = os.path.join( dir, file )
        if os.path.isdir( path ):
            rmdirx( path )
        else:
            os.unlink( path )
    os.rmdir( dir )